package com.ww7h.ui.base.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.ww7h.ui.mvvm.v.ViewCommon

/**
 * ================================================
 * 描述：
 * 来源：     Android Studio.
 * 项目名：   BigObj
 * 包名：     com.ww7h.common.base
 * 创建时间：  2020/11/3 02:11
 * @author   ww
 * ================================================
 */
abstract class BaseFragment<VDB : ViewDataBinding>: Fragment() {

    protected lateinit var defaultViewDataBinding: VDB
    protected val viewCommon: ViewCommon by lazy {
        ViewCommon()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        defaultViewDataBinding = getViewDataBinding(inflater, container, getContentView())
        return defaultViewDataBinding.root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
    }

    protected open fun getTitle(): String? {
        return javaClass.simpleName
    }

    protected abstract fun getContentView(): Int

    protected fun <VDB : ViewDataBinding> getViewDataBinding(
        inflater: LayoutInflater,
        viewGroup: ViewGroup?,
        layoutId: Int
    ): VDB {
        return viewCommon.getViewDataBinding(inflater, viewGroup, layoutId)
    }

    protected open fun clearUseViewDataBindingArrayCache(layoutId: Int) {
        viewCommon.clearUseViewDataBindingArrayCache(layoutId)
    }


}